package com.reebake.ideal.redis.util;

import cn.hutool.cache.Cache;
import cn.hutool.cache.impl.CacheObj;
import cn.hutool.core.lang.func.Func0;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Iterator;
import java.util.concurrent.TimeUnit;

/**
 * 缓存工具
 */
public class RedisCacheUtil implements Cache<Object, Object> {
    private final RedisTemplate<Object, Object> redisTemplate;

    public RedisCacheUtil(RedisTemplate<Object, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public int capacity() {
        return 0;
    }

    @Override
    public long timeout() {
        return -1;
    }

    @Override
    public void put(Object key, Object object) {
        put(key, object, timeout());
    }

    @Override
    public void put(Object key, Object object, long timeout) {
        redisTemplate.boundValueOps(key).set(object, timeout, TimeUnit.MILLISECONDS);
    }

    @Override
    public Object get(Object key, boolean isUpdateLastAccess, Func0<Object> supplier) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object get(Object key, boolean isUpdateLastAccess, long timeout, Func0<Object> supplier) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object get(Object key, boolean isUpdateLastAccess) {
        return redisTemplate.boundValueOps(key).get();
    }

    @Override
    public Iterator<CacheObj<Object, Object>> cacheObjIterator() {
        throw new UnsupportedOperationException();
    }

    @Override
    public int prune() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isFull() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void remove(Object key) {

    }

    @Override
    public void clear() {

    }

    @Override
    public int size() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isEmpty() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean containsKey(Object key) {
        return false;
    }

    @Override
    public Iterator<Object> iterator() {
        throw new UnsupportedOperationException();
    }
}
